# Author : Zhichao
# date : week07


# P67  "Don't panic!" => list => "on tap"
phrase = "Don't panic!"
plist = list(phrase)  # str 转换 list 使用的方法是 list(str)
print(phrase)
print(plist)

for i in range(4):
    # 循环执行4次 删除末位 使用方法 pop()
    plist.pop()
print(plist)
plist.pop(0)
print(plist)
plist.remove("'")
print(plist)
# extend ==> plist + ["a","p"]
plist.extend([plist.pop(),plist.pop()]) # 运算顺序，（1*（5+1））
#['o','n','t',' ']   a           p
print(plist)

plist.insert(2,plist.pop(3))
#                   ' '
print(plist)
new_phrase = ''.join(plist) #? ''.join() list 转换 str
print("plist=",plist) # list的方法会打乱和改变list的内容
print("new_phrase=",new_phrase)

# P78
book = "The Hitchhiker's Guide to the Galaxy"
booklist = list(book)
print(booklist)

booklist[0:3]
''.join(booklist[0:3])
''.join(booklist[-6:])
print(booklist)

# P79

backwards = booklist[::-1]
''.join(backwards)
print(backwards)


every_other = booklist[::2]
''.join(every_other)
print(every_other)


''.join(booklist[4:14])
''.join(booklist[13:3:-1])

# p82
phrase = "Don't panic!"
plist = list(phrase)
print(phrase)
print(plist)
new_phrase = ''.join(plist[1:3])
new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])
print(plist)
print(new_phrase)

# P88
paranoid_android = "Marvin, the Paranoid Android"
letters = list(paranoid_android)
for char in letters[:6]:
    print('\t', char)
for char in letters[-7:]:
    print('\t'*2, char)
for char in letters[12:20]:
    print('\t'*3,char)
